// pages/doctorlogin/doctorlogin.js

//获取应用实例
var app = getApp()
Page({
  data: {
    motto: '欢迎登录糖膳藏客户端',
    userInfo: {},
    userName: '',
    userPassword: '',
    id_token: '',
    responseData: '',
  },
  //事件处理函数
  bindViewTap: function () {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  userNameInput: function (e) {
    this.setData({
      userName: e.detail.value
    })
  },
  userPasswordInput: function (e) {
    this.setData({
      userPassword: e.detail.value
    })
    console.log(e.detail.value)
  },
  logIn: function () {
    var that = this
    wx.request({
      url: app.globalData.url + '/API/login',
      data: {
        account: this.data.userName,
        password: this.data.userPassword,
      },
      method: 'get',
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {
        console.log("调用API成功");
        console.log(res.data.message);
        if (res.data.message == "ok") {
          wx.showToast({
            title: '登陆成功',
          })
          wx.navigateTo({
            url: '../doctor/doctor',
          })
        }
        else {
          wx.showModal({
            title: '提示',
            content: '用户名或者密码错误',
            showCancel: false
          })
        }
      },
      fail: function (res) {
        console.log(res.data);
        console.log('失败')
      }
    })

  },
  onLoad: function () {
    console.log('onLoad')
    var that = this
    //调用应用实例的方法获取全局数据
    /*app.getUserInfo(function (userInfo) {
      //更新数据
      that.setData({
        userInfo: userInfo
      })
    })*/
  },
  onShow: function () {
    console.log('doctorlogin is show')
  },
  onReady: function () {
    console.log('doctorlogin is on ready')
  },
  onHide: function () {
    console.log('doctorlogin is on hide')
  },
  onUnload: function () {
    console.log('doctorlogin is on unload')
  },
  //分享函数
  onShareAppMessage: function () {
  }

})